export const comparedArr = (old, update) => {
  let res = true;
  // 先比较长度
  if (old.length != update.length) {
    res = false;
  }
  // 再比较id（根据数组中对象的某个属性比较）
  let oldIds = old.map((item) => {
    return item;
  });
  let updateIds = update.map((item) => {
    return item;
  });
  for (let i = 0, len = oldIds.length; i < len; i++) {
    if (updateIds.indexOf(oldIds[i]) == -1) {
      res = false;
    }
  }
  return res;
};

export const throttle = (fn, wait) => {
  // console.log('wait', wait);
  let timer;
  return function () {
    if (!timer) {
      timer = setTimeout(() => {
        timer = null;
        fn.apply(this, arguments);
      }, wait);
    }
  };
};

export const debounce = (fn, wait) => {
  var timer = null;
  return function () {
    if (timer !== null) {
      clearTimeout(timer);
    }
    timer = setTimeout(fn, wait);
  };
};

export const removeListItem = (arr, item) => {
  return arr.filter((f) => f != item);
};

export const getCurrentTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hours = String(now.getHours()).padStart(2, "0");
  const minutes = String(now.getMinutes()).padStart(2, "0");
  const seconds = String(now.getSeconds()).padStart(2, "0");
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
